package org.mango.basic;

import java.util.Scanner;

/**
 * 
 * @author 戴礼明
 *日期： 2016-4-21
 *content：利用穷举法计算鸡和兔的问题
 */
public class ExhaustiveMethod {

	 static int i,j; 
	
	 public static boolean caculate(int head,int footer){
		  
		 boolean isContain=false;
		 
             for(i=0;i<=head;i++){
            	 j=head-i;
            	  if(2*i+4*j==footer){
            		  isContain=true;
            		  return true;
            	  } 
             }
             return isContain;
	 }
	
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		
   do{		
		System.out.println("请输入鸡和兔的总的头数，脚的总数");
		int head=scanner.nextInt();
		int footer=scanner.nextInt();
		if(caculate(head, footer)){
			System.out.println("有"+i+"只鸡和"+j+"只兔！");
			break;
		}else{
			System.out.println("输入错误！");
		}
   }while(true);
	}
}
